#version 450 core

layout(location = 0) in vec3 normal;
layout(location = 1) in vec3 fragPos;
layout(location = 0) out vec4 fragColor;

uniform mat4 modelMatrix;
uniform mat4 normalMatrix;
uniform mat4 viewProjectionMatrix;
struct Material {
    vec3 color;
    float shininess;
};
uniform Material material;
uniform vec3 cameraPos;
struct Light {
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;
    vec3 position;
};
layout(binding = 0) uniform LightBlock {
    Light light;
};

void main() {
    vec3 ambient = light.ambient * material.color;
    vec3 lightDir = normalize(light.position - fragPos);
    vec3 diffuse = max(dot(lightDir, normal), 0.0f) * light.diffuse;
    vec3 reflectDir = reflect(-lightDir, normal);
    vec3 viewDir = normalize(cameraPos - fragPos);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0f), material.shininess);
    vec3 specular = spec * light.specular * material.color;
    vec3 result = ambient + diffuse + specular;
    fragColor = vec4(result, 1.0f);
    // fragColor = vec4(vec3(gl_FragCoord.z), 1.0f);
}
